package com.tz.colawallet.ui.fragment;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tz.colawallet.R;
import com.tz.colawallet.basecode.base.BaseFragment;
import com.tz.colawallet.basecode.util.SPUtils;
import com.tz.colawallet.bean.UserMessage;
import com.tz.colawallet.constant.Key;
import com.tz.colawallet.ui.activity.LoginActivity;
import com.tz.colawallet.ui.activity.ResetActivity;
import com.tz.colawallet.ui.activity.SuggestActivity;
import com.tz.colawallet.ui.biz.MainThirdFragBiz;
import com.tz.colawallet.ui.component.DaggerMainThirdFragComponent;
import com.tz.colawallet.ui.contract.MainThirdFragContract;
import com.tz.colawallet.ui.module.MainThirdFragModule;
import com.tz.colawallet.ui.presenter.MainThirdFragPresenter;

import javax.inject.Inject;

public class MainThirdFrag extends BaseFragment implements MainThirdFragContract.View {
    @Inject
    MainThirdFragPresenter presenter;
    @Inject
    MainThirdFragBiz biz;

    ImageView head;
    TextView name;
    TextView phone;
    LinearLayout suggestLayout;
    LinearLayout resetPasswordLayout;

    @Override
    protected void setup() {
        super.setup();
        DaggerMainThirdFragComponent.builder().mainThirdFragModule(new MainThirdFragModule(this)).build().inject(this);
        presenter.setBiz(biz);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.fragment_main_third;
    }

    @Override
    protected void initTitle(View view) {

    }

    @Override
    protected void init(View view) {
        view.findViewById(R.id.out_img).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SPUtils.put(getActivity(), Key.TOKEN, "");
                switchActivityAndFinish(LoginActivity.class, null);
            }
        });
        head = view.findViewById(R.id.head);
        name = view.findViewById(R.id.name);
        phone = view.findViewById(R.id.phone);
        suggestLayout = view.findViewById(R.id.suggest_layout);
        resetPasswordLayout = view.findViewById(R.id.reset_password_layout);


        suggestLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switchActivity(SuggestActivity.class, null);
            }
        });

        resetPasswordLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switchActivity(ResetActivity.class, null);
            }
        });

        presenter.getUserDetail();
    }

    @Override
    protected void initData() {

    }

    @Override
    public Context curContext() {
        return getActivity();
    }

    @Override
    public void showUserDetail(UserMessage o) {
        name.setText(o.getUsername());
        phone.setText(o.getTel());
        if (o.getSex() == 0) {
            head.setImageResource(R.mipmap.head_nam);
        } else {
            head.setImageResource(R.mipmap.head_wonam);
        }
    }

    @Override
    public void showMsg(String msg) {
        showToast(msg);
    }

}
